Skip to content

Lesson 4. A note on debugging

Updated pdexter 2022-12-19

When writing our ruleset script, debugging can be tricky, as it occurs in the browser process. However, we can view logging through the debugger console of the browser.

  • For most browsers, press F12 to raise the debugger console.
  • You may need to click on the Console tab

Example Debug Console (Firefox)

The following is the output shown when the user changes the value of the field "Decommissioned Date" in the previous lesson.

Console logging from rulesets comes prefixed with "RSLog:" and also denotes the source "jayrule-ruleset-script" on the right side (unless configured otherwise)

As you can see, there is already a lot of logging coming from the ruleset, without us having to specifically log anything in the ruleset.

Adding your own logging

Within rulesets, we have a specific object used for logging: ntf.logger

This is used in preference to javascript's console object, since there is no console object available in server-side rulesets (we look at those later).

Function Description
ntf.logger.info(text) Writes a line to the console or log, in the basic style.
ntf.logger.debug(text) Writes a line to the console or log, in the debug style.
ntf.logger.error(text) Writes a line to the console or log, in the error style.

Step 1. Write your own logging

  • Open the Acme Rental Car - OnFieldChange ruleset completed in Lesson 3
  • In the ruleAction function for ruleSetLRDNow, add the following lines
ntf.logger.info('This is an information log line.');
ntf.logger.debug('This is a debug log line.');
ntf.logger.error('This is an error log line.');
  • Open an existing or new Acme Rental Car document.
  • Open your debugger console by pressing F12; click on the Console tab if necessary.
  • On the document, click the button "Set to Now".
  • Observe the output in the debugger console.

You should see something like the following: